﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Text;

namespace SqlToolkit.Oracle.Schema
{
    //USER_PROCEDURES
   // Columns
   //___________________________
   
   //OBJECT_NAME
   //   Name of the object : top level function/procedure/package name
   //PROCEDURE_NAME
   //   Name of the procedure
   //AGGREGATE
   //   Is it an aggregate function ?
   //PIPELINED
   //   Is it a pipelined table function ?
   //IMPLTYPEOWNER
   //   Name of the owner of the implementation type (if any)
   //IMPLTYPENAME
   //   Name of the implementation type (if any)
   //PARALLEL
   //   Is the procedure parallel enabled ?
   //INTERFACE
   //   --
   //DETERMINISTIC
   //   --
   //AUTHID
   //   --

    //OBJECT_NAME,PROCEDURE_NAME,AGGREGATE,PIPELINED,IMPLTYPEOWNER,IMPLTYPENAME,PARALLEL,INTERFACE,DETERMINISTIC,AUTHID
    public class SqlDbProcedure : SqlBase
    {
        private string _objectName = string.Empty;
        private string _procedureName = string.Empty;
        private string _aggregate = string.Empty;
        private string _pipelined = string.Empty;
        private string _implTypeName = string.Empty;
        private string _parallel = string.Empty;
        private string _interface = string.Empty;
        private string _deterministic = string.Empty;
        private string _authid = string.Empty;

        public string ObjectName 
        {
            get{return _objectName;}
            set { _objectName = value; }
        }

        public string ProcedureName
        {
            get { return _procedureName; }
            set { _procedureName = value; }
        }

        public string Aggregate
        {
            get { return _aggregate; }
            set { _aggregate = value; }
        }

        public string Pipelined
        {
            get { return _pipelined; }
            set { _pipelined = value; }
        }

        public string ImplTypeName
        {
            get { return _implTypeName; }
            set { _implTypeName = value; }
        }
        public string Parallel
        {
            get { return _parallel; }
            set { _parallel = value; }
        }
        public string Interface
        {
            get { return _interface; }
            set { _interface = value; }
        }
        public string Deterministic
        {
            get { return _deterministic; }
            set { _deterministic = value; }
        }
        public string AuthID
        {
            get { return _authid; }
            set { _authid = value; }
        }

        public static SqlDbProcedure Build(IDataReader r)
        {
            SqlDbProcedure ret = new SqlDbProcedure();

            //OBJECT_NAME,PROCEDURE_NAME,AGGREGATE,PIPELINED,IMPLTYPEOWNER,IMPLTYPENAME,PARALLEL,INTERFACE,DETERMINISTIC,AUTHID

            if (null != r)
            {

                if (!r.IsDBNull(0))
                {
                    ret._objectName = Convert.ToString(r.GetValue(0));
                }


                if (!r.IsDBNull(1))
                {
                    ret._procedureName = Convert.ToString(r.GetValue(1));
                }


                if (!r.IsDBNull(2))
                {
                    ret._aggregate = Convert.ToString(r.GetValue(2));
                }


                if (!r.IsDBNull(3))
                {
                    ret._pipelined = Convert.ToString(r.GetValue(3));
                }


                if (!r.IsDBNull(4))
                {
                    ret._implTypeName = Convert.ToString(r.GetValue(4));
                }


                if (!r.IsDBNull(5))
                {
                    ret._parallel = Convert.ToString(r.GetValue(5));
                }


                if (!r.IsDBNull(6))
                {
                    ret._deterministic = Convert.ToString(r.GetValue(6));
                }

                if (!r.IsDBNull(7))
                {
                    ret._authid = Convert.ToString(r.GetValue(7));
                }

            }
            else
            {
                return null;
            }

            return ret;

        }

        public static SqlDbProcedureCollection BuildCollection(IDataReader r)
        {
            SqlDbProcedureCollection ret = new SqlDbProcedureCollection();

            while (r.Read())
            {
                ret.Add(Build(r));
            }

            if (ret.Count == 0) return null;

            return ret;
        }

        


    }
}
